package com.ynny.librarysystemmanager.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;

public class LoginInterceptor implements HandlerInterceptor {

    // 前置拦截器
    // true 放行
    // false 拦截
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {

//        System.out.println("前置拦截器");

//        if (request.getRequestURL())


        if (request.getSession()
                .getAttribute("SESSION_USER") != null) {
            return true;
        }


        //get请求
        response.sendRedirect("/login");


        return false;
    }
}
